import 'package:winkai/generated/json/base/json_field.dart';
import 'package:winkai/generated/json/role_info.g.dart';
import 'package:winkai/db/database.dart';
import 'package:winkai/ext/ext.dart';
import 'dart:convert';

export 'package:winkai/generated/json/role_info.g.dart';

@JsonSerializable()
class RoleInfo {
  String? id;
  String? name;
  int age = 0;
  @JSONField(name: "about_me")
  String? aboutMe;
  @JSONField(name: "render_style")
  String? renderStyle;
  String? avatar;
  List<String>? greetings;

  RoleInfo();

  factory RoleInfo.fromJson(Map<String, dynamic> json) =>
      $RoleInfoFromJson(json);

  factory RoleInfo.fromUserTbData(UserTbData? userInfoData) {
    var info = RoleInfo();
    info.id = userInfoData?.id;
    info.name = userInfoData?.nickname;
    info.aboutMe = userInfoData?.aboutMe;
    info.age = userInfoData?.age ?? 0;
    info.renderStyle = userInfoData?.renderStyle;
    info.avatar = userInfoData?.avatar;
    info.greetings = userInfoData?.greetings.toStringList;
    return info;
  }

  Map<String, dynamic> toJson() => $RoleInfoToJson(this);

  @override
  String toString() {
    return jsonEncode(this);
  }
}
